package com.wn55.hrms.web.controller;

import com.github.pagehelper.PageInfo;
import com.wn55.hrms.entity.OverTime;
import com.wn55.hrms.entity.RecruitChannel;
import com.wn55.hrms.service.OverTimeService;
import com.wn55.hrms.util.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author Mr.bai~
 * @version 1.0
 * @date 2022/5/5 23:15
 */
@RestController
@RequestMapping("overTime")
@Api(value = "本接口是用来操作加班表功能")
public class OverTimeController {

    @Autowired
    OverTimeService overTimeService;

    @GetMapping("/overTimeList")
    @ApiOperation(value = "分页查询渠道列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",dataType = "int",name="now",value = "查询当前页",required = false,defaultValue = "1"),
            @ApiImplicitParam(paramType = "query",dataType = "int",name="size",value ="查询每页条数",required = false,defaultValue = "2"),
            @ApiImplicitParam(paramType = "query",dataType = "string",name="eName",value = "员工名称",required = false),
            @ApiImplicitParam(paramType = "query",dataType = "string",name="type",value = "加班类型",required = false),
    })
    public ResultResponse<PageInfo<OverTime>> overTimeList(
            @RequestParam(value = "now", defaultValue = "1") Integer now,
            @RequestParam(value = "size", defaultValue = "2") Integer size,
            String eName, String type){
        ResultResponse<PageInfo<OverTime>> result = null;
        try {

            PageInfo<OverTime> pageInfo = overTimeService.queryChannel(now, size, eName, type);
            result = new ResultResponse<>(200, "查询成功", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            result = new ResultResponse<>(404, "查询失败");
        }
        return result;
    }
    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "根据标识ID删除渠道")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path",dataType = "int",name = "id",value = "加班记录的ID标识")
    })
    public ResultResponse<Void> delete(@PathVariable("id") int id) {

        ResultResponse<Void> result = null;

        try {
            overTimeService.removeBykey(id);
            result = new ResultResponse<>(200, "删除加班成功!");
        } catch (Exception e) {
            e.printStackTrace();
            result = new ResultResponse<>(201, "删除加班失败!");
        }
        return result;
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加渠道信息")
    public ResultResponse<Void> addOverTime(@RequestBody OverTime overTime) {
        System.out.println(overTime.geteId());
        ResultResponse<Void> result = null;
        try {
            overTime.setIsdelete(0);
            overTimeService.addOverTime(overTime);
            result = new ResultResponse<>(200, "添加加班成功!");
        } catch (Exception e) {
            e.printStackTrace();
            result = new ResultResponse<>(201, "添加加班失败!");
        }
        return result;
    }

    @PutMapping("/modify")
    @ApiOperation(value = "添加渠道信息")
    public ResultResponse<Void> modifyOverTime(@RequestBody OverTime overTime) {
        System.out.println(overTime.geteId());
        ResultResponse<Void> result = null;
        try {
            overTime.setIsdelete(0);
            overTimeService.modifyOverTime(overTime);
            result = new ResultResponse<>(200, "修改加班成功!");
        } catch (Exception e) {
            e.printStackTrace();
            result = new ResultResponse<>(201, "修改加班失败!");
        }
        return result;
    }

}
